<template>
  <div class="wallet-content">
    <div class="moneyicon">
      <img src="@/assets/img/img_wdqb.png">
    </div>
    <div class="money">￥{{ money }}</div>
    <div class="iptbox">
      <input v-model="value" placeholder="请输入提现金额" class="ipt" type="number">
    </div>
    <br>
    <br>
    <div class="iptbox">
      <input v-model="value2" placeholder="请输入提现银行卡" class="ipt" type="number">
    </div>
    <div class="btn" @click="Suk_tixian">提现</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: null,
      value2: null,
      money: null,
      zhifubao: null
    };
  },
  beforeCreate: function () {
    //创建前
  },
  created: function () {
    this.getstatus();
    //创建后
  },
  beforeMount: function () {
    //挂载前
  },
  mounted: function () {
    //挂载后
  },
  beforeUpdate: function () {
    //更新前
  },
  update: function () {
    //更新后
  },
  methods: {
    Suk_tixian() {
      let that = this;
      if (that.value == null || that.value == '') {
        that.$toast.fail({
          message: "请输入提现金额"
        });
      } else if (that.value2 == null || that.value2 == '') {
        that.$toast.fail({
          message: "请输入银行卡账号"
        });
      } else {
        that.$toast.loading({
          message: "加载中..."
        });
        var Sukdata = {
          payZhifu: that.zhifubao,
          money: that.value,
          bank: that.value2,
          userId: localStorage.getItem("userid")
        };
        that.axios
          .post(
            that.baseUrl + "/user/ZhifubaoTiXian",
            that.Qs.stringify(Sukdata),
            {
              headers: {
                "Content-Type": "application/x-www-form-urlencoded"
              }
            }
          )
          .then(function (res) {
            if (res.request.status === 200) {
              if (res.data.meta.code == 200) {
                if (res.data.data == "提现失败") {
                  that.getstatus();
                  that.$toast.fail({
                    message: "提现失败"
                  });
                } else if (res.data.data == "提现成功") {
                  that.getstatus();
                  that.$toast.success({
                    message: "支付宝提现成功！请等待工作人员审核入账！！"
                  });
                } else if (res.data.data == "银行卡提现成功") {
                  that.getstatus();
                  that.$toast.success({
                    message: "银行卡提现成功！请等待工作人员审核入账！！"
                  });
                } else if (res.data.data == "提现金额大于账户余额") {
                  that.getstatus();
                  that.$toast({
                    message: "提现金额大于账户余额"
                  });
                } else {
                  that.getstatus();
                  that.$toast({
                    message: res.data.data
                  });
                }
              } else if (res.data.meta.code == -1) {
                that.getstatus();
                that.$toast({
                  message: "请绑定支付宝账号"
                });
              } else if (res.data.meta.code == -2) {
                that.getstatus();
                that.$toast({
                  message: "提现金额不能少于0.1元"
                });
              }
            }
          });
      }
    }
    ,
    //获取用户身份
    getstatus() {
      let that = this;
      var Sukdata = {
        id: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/user/userOne", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function (res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data);
              that.money = res.data.data.money;
              that.zhifubao = res.data.data.payZhifu;
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.wallet-content {
  font-size: 0.3rem;
}

.moneyicon {
  text-align: center;
  margin: 1rem;

  img {
    width: 2.43rem;
    height: 2.43rem;
  }
}

.money {
  text-align: center;
  font-size: 1.5rem;
  text-indent: -0.8rem;
  color: #000;
}

.btn {
  width: 90%;
  height: 1.3rem;
  line-height: 1.3rem;
  margin: 0 auto;
  background: rgb(255, 159, 57);
  color: #fff;
  text-align: center;
  font-size: 0.5rem;
  border-radius: 0.8rem;
  margin-top: 2.5rem;
}

.iptbox {
  text-align: center;

  .ipt {
    border: none;
    font-size: 0.45rem;
    text-align: center;
  }
}
</style>
